package com.qidian.md.controller;

import com.qidian.md.service.impl.ClientServiceImpl;
import com.qidian.mes.pojo.md.Client;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 18林梦雅
 * @Company 起点编程
 * @Time 2023/10/26 14:34
 * @Description
 */
@RestController
@RequestMapping("/client")
@CrossOrigin
public class ClientController {
    @Autowired
    ClientServiceImpl clientService;

    @GetMapping("/list")
    public MESResult list(Client client, @RequestParam(defaultValue="1")int page, @RequestParam(defaultValue="10")int limit){
        System.out.println(client+"++++++++++++++++++++++++++++++++++++++++++");
        return clientService.queryByPage(client,page,limit);
    }


    /**controller
     * 添加客户接口
     * 请求方法： POST
     * url： /client/save
     * 参数：
     * 格式：JSON
     * 参数的内容：clientname,clientPass
     * 响应结果：
     * 成功： ｛code:200,msg:"",data:null｝
     * 失败：
     * 失败｛code:500,msg:"错误信息",data:null｝
     * 重名 {code: 300,msg:"名字重复",data:""}
     * @param client
     * @return
     */
    @PostMapping("/save")
    public MESResult save(@RequestBody Client client){
        return clientService.addClient(client);
    }



    /**controller
     * 请求方法： GET
     * url : /client/get
     * 参数： clientId(必须，要查询的客户编号)
     * 响应：
     *  成功： `{code:200,msg:"",data:{clientId:1,clientname:"大锤",clientPass:"123".....}}`
     *  失败：`{code:400,msg:"没有数据",data:null}`
     * @param clientId
     * @return
     */
    @GetMapping("/get")
    public MESResult get(Long clientId){
        return   clientService.queryById(clientId);
    }

    /**编辑客户
    请求方法： PUT/POST
    url： /client/edit
    参数 : clientId(必须),clientname,clientPass,clientStatus
    响应结果：
    成功： ｛code:200,msg:"",data:null｝
    失败：
    失败｛code:500,msg:"错误信息",data:null｝
    重名 {code: 300,msg:"名字重复",data:""}
    */
    @PutMapping("/update")
    public MESResult update(@RequestBody Client client){
        System.out.println(client+"+++++++++++++++++++++++++++++++++++++++++");
        return clientService.update(client);
    }

    /**
     * 根据Id删除客户数据,删除是将是否启用改为0,将搜索显示是更改为除了0其他显示
     * @param clientId
     * @return
     */
    @DeleteMapping("/{clientId}")
    public MESResult deleteById(@PathVariable Long clientId){//注意这里的注解是因为用字段为url
        return clientService.deleteUpdateStatus(clientId);
    };


    /**
     * 批量删除,将启用状态变为0
     * @param clientId
     * @return
     */
    @DeleteMapping("/deletes")
    public MESResult deleteSelect( Long[] clientId){
        System.out.println(clientId+"+++++++++++++++++++++++++++++++++++++++++++++++");
        return clientService.deleteUpdateSelect(clientId);
    };















}
